import { exec } from "child_process";

export function enableProxy({ host = "127.0.0.1", port = 8123 }) {
	return new Promise((r, j) => {
		exec(
			`"${process.env.SETPROXY_EXE_PATH}" http=${host}:${port} https=${host}:${port}`,
			(error, stdout, stderr) => {
				if (error == null) {
					r(true);
				} else {
					j(error);
				}
			}
		);
	});
}

export function stopProxy() {
	return new Promise((r, j) => {
		exec(
			`"${process.env.SETPROXY_EXE_PATH}" stop`,
			(error, stdout, stderr) => {
				if (error == null) {
					r(true);
				} else {
					j(error);
				}
			}
		);
	});
}
